**************************************************************************************************
*number of lenders over time who issue high interest loans

*rate spread greater than 4%
use "$data/demog_meta.dta", clear
keep respond as_of rate_spread loan_am
drop if rate_spread==.
gen treat=0
replace treat=1 if rate_spread>4
sort respond as_of
quietly by respond as_of:  gen dup = cond(_N==1,0,_n)
keep if dup==1
collapse (sum) dup, by(as_of treat)
twoway conn dup as_of if treat==1&as_of>=2010||conn dup as_of if treat==0&as_of>=2010,  xline(2014) ytitle(Nb. of Lenders)/*
*/ xtitle(Year) graphregion(color(white)) bgcolor(white) /*
*/ legend(label(1 "Rate Spread Above 4%") label(2 "Rate Spread Below 4%"))
graph export "$figures/nb_high_interest_lenders.eps", as(eps) preview(on) replace
graph export "$figures/nb_high_interest_lenders.pdf", as(pdf) replace


******************************************************************************************************
*distribution of HOEPA lenders excluding zeros
use "$data/demog_meta.dta", clear
keep respond as_of rate_spread loan_am

*tag loans that become hoepa post 2014
gen hoepa=0
replace hoepa=1 if rate_spread>=8.5&loan_am<50
replace hoepa=1 if rate_spread>=6.5&loan_am>=50

*count the total number of hoepa loans issued by each lender per year
sort respond as_of
by respond as_of: egen nb_hoepa=total(hoepa)


*count the total number of loans issued by each lender per year
sort respond as_of
gen count=1
by respond as_of: egen nb_loans=total(count)


*gen percent of loans that are hoepa
gen percent_hoepa=nb_hoepa/nb_loans


*distribution of hoepa issuer lenders non-zero only
sum percent_hoepa, detail
hist percent_hoepa if percent_hoepa~=0, density ytitle(Percent of HOEPA Loans in Total Lender Portfolio)/*
*/ ytitle(density) graphregion(color(white)) bgcolor(white) xtitle("") color(navy*0.7)
graph export "$figures/percent_hoepa_nonzero.eps", as(eps) preview(on) replace


hist percent_hoepa if percent_hoepa~=0&as_of<2014, density ytitle(Percent of HOEPA Loans in Total Lender Portfolio Pre 2014)/*
*/ ytitle(density) graphregion(color(white)) bgcolor(white) xtitle("") color(navy*0.7)
graph export "$figures/percent_hoepa_pre2014_nonzero.eps", as(eps) preview(on) replace

hist percent_hoepa if percent_hoepa~=0&as_of>=2014, density ytitle(Percent of HOEPA Loans in Total Lender Portfolio Post 2014)/*
*/ ytitle(density) graphregion(color(white)) bgcolor(white) xtitle("") color(navy*0.7)
graph export "$figures/percent_hoepa_post2014_nonzero.eps", as(eps) preview(on) replace


*distribution of hoepa issuer lenders including zero
hist percent_hoepa, density ytitle(Percent of HOEPA Loans in Total Lender Portfolio)/*
*/ ytitle(density) graphregion(color(white)) bgcolor(white) xtitle("") color(navy*0.7)
graph export "$figures/percent_hoepa.eps", as(eps) preview(on) replace


hist percent_hoepa if as_of<2014, density ytitle(Percent of HOEPA Loans in Total Lender Portfolio Pre 2014)/*
*/ ytitle(density) graphregion(color(white)) bgcolor(white) xtitle("") color(navy*0.7)
graph export "$figures/percent_hoepa_pre2014.eps", as(eps) preview(on) replace

hist percent_hoepa if as_of>=2014, density ytitle(Percent of HOEPA Loans in Total Lender Portfolio Post 2014)/*
*/ ytitle(density) graphregion(color(white)) bgcolor(white) xtitle("") color(navy*0.7)
graph export "$figures/percent_hoepa_post2014.eps", as(eps) preview(on) replace

























